package com.arsn.myf.system.controller;

import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.arsn.myf.system.entity.ErrorLog;
import com.arsn.myf.system.service.ErrorLogService;
import com.arsn.myf.system.vo.ErrorLogVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;
import java.util.Arrays;

/**
 * 错误日志
 * @author zhongrj
 * @since 2022-08-11
 */
@RestController
@RequestMapping("/errorLog")
@AllArgsConstructor
@Api(value = "错误日志", tags = "错误日志")
public class ErrorLogController {

    private final ErrorLogService errorLogService;


    /**
     * 查询错误日志的分页数据
     * @param page
     * @param errorLog
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询错误日志的分页数据")
    public R list(Page<ErrorLog> page, ErrorLog errorLog){
        return R.data(errorLogService.page(page,new QueryWrapper<>(errorLog)));
    }


    /**
     * 自定义查询错误日志的分页数据
     * @param page
     * @param errorLog
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "自定义查询错误日志的分页数据")
    public R page(Page<ErrorLogVO> page, ErrorLogVO errorLog){
        return R.data(errorLogService.selectPageErrorLogList(page,errorLog));
    }


    /**
     * 错误日志详情信息
     * @param errorLog
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "错误日志详情信息")
    public R detail(ErrorLog errorLog){
        return R.data(errorLogService.getOne(new QueryWrapper<>(errorLog)));
    }


    /**
     * 错误日志新增
     * @param errorLog
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "错误日志新增")
    public R save(@RequestBody ErrorLog errorLog){
        return R.status(errorLogService.save(errorLog));
    }

    /**
     * 错误日志修改
     * @param errorLog
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "错误日志修改")
    public R update(@RequestBody ErrorLog errorLog){
        return R.status(errorLogService.updateById(errorLog));
    }


    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(errorLogService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }
}
